<!DOCTYPE html>
<html>
<head>
    <title>鹿鹿泽会员综合信息</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="icon" href="{{ url_for('static', filename='favicon.ico') }}" type="image/x-icon">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/badge.css') }}">
    <style>
        /* 全局样式 */
        body {
            background-color: #faf8f5;
            color: #4a4a4a;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            line-height: 1.6;
            padding: 20px;
            margin: 0;
        }

        /* 保护包含的 show_ins_info.html 样式 */
        #sessionInfoBox {
            position: fixed !important;
            top: 0 !important;
            left: 0 !important;
            width: 100% !important;
            background-color: #ededed !important;
            padding: 8px !important;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1) !important;
            z-index: 1000 !important;
            margin-bottom: 22px !important;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
        }
        
        #sessionInfoBox * {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
            font-size: 10px !important;
        }
        
        /* 为 body 添加顶部内边距，避免内容被状态栏遮挡 */
        body {
            padding-top: 50px !important;
        }
        
        #sessionInfo {
            all: initial;
            display: flex;
            align-items: center;
            gap: 10px;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            font-size: 10px !important;
        }
        
        #sessionInfo span {
            font-size: 10px !important;
        }
        
        .session-name {
            all: initial;
            font-size: 10px;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
        }
        
        #logout, #goIndex {
            all: initial;
            margin: 0;
            padding: 2px 4px;
            font-size: 8px;
            height: 18px;
            width: 40px;
            line-height: 1;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            cursor: pointer;
            background-color: #f0f0f0;
            border: 1px solid #ccc;
            border-radius: 2px;
            text-align: center;
        }
        
        #logout:hover, #goIndex:hover {
            background-color: #e0e0e0;
        }
        
        #dataBaseType {
            all: initial;
            margin-left: 10px;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            font-size: 10px !important;
        }
        
        #sessionInsId, #sessionInsName, #sessionInsRole, #showRole {
            font-size: 10px !important;
        }

        /* 标题样式 */
        h2 {
            color: #8B4513;
            font-size: 24px;
            font-weight: 600;
            margin-bottom: 20px;
            text-align: center;
            padding: 15px;
            background: #F5DEB3;
            border-radius: 8px;
            border-bottom: 3px solid #D2B48C;
        }

        h4 {
            color: #8B4513;
            font-size: 16px;
            font-weight: 500;
            margin: 0;
        }

        /* 搜索区域样式 */
        .search-section {
            background: white;
            padding: 20px;
            border-radius: 12px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.08);
            margin-bottom: 25px;
        }

        .form-row {
            display: flex;
            align-items: center;
            gap: 15px;
        }
        
        .form-row h4 {
            width: auto !important;
            min-width: 80px;
            margin: 0 10px 0 0 !important;
        }

        #cusNameInput {
            margin-bottom: 20px;
            padding: 12px 16px;
            border: 2px solid #e2e8f0;
            border-radius: 8px;
            font-size: 14px;
            width: 138px !important;
            max-width: 138px !important;
            min-width: 138px !important;
            transition: border-color 0.3s ease;
            box-sizing: border-box !important;
        }

        #cusNameInput:focus {
            outline: none;
            border-color: #667eea;
            box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
        }

        /* 会员列表样式 */
        #cusNameList {
            position: absolute;
            background: white;
            border: 1px solid #e2e8f0;
            border-radius: 8px;
            box-shadow: 0 4px 15px rgba(0,0,0,0.1);
            max-height: 180px !important;
            overflow-y: auto;
            z-index: 1000;
            width: 180px !important;
        }

        #cusNameList li {
            padding: 12px 16px;
            cursor: pointer;
            border-bottom: 1px solid #f1f5f9;
            transition: background-color 0.2s ease;
        }

        #cusNameList li:hover {
            background-color: #f8fafc;
        }

        #cusNameList li:last-child {
            border-bottom: none;
        }

        /* 信息卡片样式 */
        .info-card {
            background: white;
            border-radius: 16px;
            padding: 25px;
            margin-bottom: 25px;
            box-shadow: 0 4px 20px rgba(0,0,0,0.08);
            border: 1px solid #f1f5f9;
        }

        .card-header {
            color: #8B4513;
            font-size: 20px;
            font-weight: 600;
            margin-bottom: 20px;
            padding-bottom: 12px;
            border-bottom: 2px solid #D2B48C;
        }

        /* 基本信息区域 */
        .basic-info-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 20px;
            margin-bottom: 25px;
        }

        .info-group {
            background: #f8fafc;
            padding: 20px;
            border-radius: 12px;
            border-left: 4px solid #c89c54;
        }

        .info-row {
            display: flex;
            align-items: center;
            margin-bottom: 12px;
            padding: 8px 0;
        }

        .info-label {
            min-width: 70px !important;
            font-weight: 500;
            color: #8B4513;
            font-size: 14px;
            background: #F5DEB3;
            padding: 6px 12px;
            border-radius: 6px;
            margin-right: 15px;
            text-align: center;
            flex-shrink: 0;
            border: 1px solid #D2B48C;
        }

        .info-value {
            color: #1e293b;
            font-size: 16px;
            font-weight: 500;
        }

        /* 照片区域 */
        .photo-section {
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
            background: #F5DEB3;
            border-radius: 12px;
            min-height: 150px;
            border: 1px solid #D2B48C;
            margin-bottom: 10px;
        }

        .photo-section img {
            max-height: 130px;
            border-radius: 8px;
            box-shadow: 0 4px 15px rgba(0,0,0,0.2);
            border: 3px solid white;
        }

        /* 购课和上课情况样式 */
        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 20px;
            margin-bottom: 25px;
        }

        .stat-item {
            background: #F5DEB3;
            padding: 20px;
            border-radius: 12px;
            color: #8B4513;
            text-align: center;
            border: 1px solid #D2B48C;
        }

        .stat-label {
            font-size: 14px;
            opacity: 0.9;
            margin-bottom: 8px;
        }

        .stat-value {
            font-size: 18px;
            font-weight: 600;
        }

        /* 详情区域 */
        .detail-section {
            background: #f8fafc;
            padding: 20px;
            border-radius: 12px;
            margin-top: 15px;
        }

        .detail-header {
            display: flex;
            align-items: center;
            margin-bottom: 15px;
            padding-bottom: 10px;
            border-bottom: 2px solid #e2e8f0;
        }

        .detail-title {
            background: #F5DEB3;
            color: #8B4513;
            padding: 8px 16px;
            border-radius: 6px;
            font-weight: 500;
            margin-right: 15px;
            border: 1px solid #D2B48C;
        }

        .detail-content {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 15px;
        }

        .detail-item {
            background: white;
            padding: 12px;
            border-radius: 8px;
            border-left: 3px solid #D2B48C;
            box-shadow: 0 2px 8px rgba(0,0,0,0.05);
        }

        /* 图表容器 */
        .chart-container {
            background: white;
            padding: 25px;
            border-radius: 16px;
            box-shadow: 0 4px 20px rgba(0,0,0,0.08);
            margin-bottom: 25px;
        }

        .chart-title {
            color: #8B4513;
            font-size: 18px;
            font-weight: 600;
            margin-bottom: 20px;
            text-align: center;
        }

        /* 分隔线 */
        hr {
            border: none;
            height: 1px;
            background: linear-gradient(90deg, transparent, #e2e8f0, transparent);
            margin: 30px 0;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .basic-info-grid {
                grid-template-columns: 1fr;
            }
            
            .stats-grid {
                grid-template-columns: 1fr;
            }
            
            .form-row {
                flex-direction: column;
                align-items: stretch;
            }
            
            #cusNameInput {
                width: 100% !important;
            }
            
            /* 移动端图表调整 */
            .chart-container {
                padding: 15px;
            }
            
            .chart-title {
                font-size: 16px;
            }
        }

        /* 动画效果 */
        .info-card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }

        .info-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 30px rgba(0,0,0,0.12);
        }

        /* 加载状态 */
        .loading {
            opacity: 0.6;
            pointer-events: none;
        }
    </style>
</head>
<body>
    {% include 'show_ins_info.html' %}
    
    <div class="search-section">
        <h2>鹿鹿泽会员综合信息</h2>
        <div class="form-row">
            <h4>会员姓名</h4>
            <input id="cusNameInput" placeholder="输入会员姓名..." oninput="handleInput();">
        </div>
        <div id="cusNameList"></div>
        <div id="insInfo" class="form-row"></div>
    </div>

    <div id="infoBox" style="display: none;">
        <!-- 基本信息卡片 -->
        <div class="info-card">
            <div class="card-header">基本信息</div>
            <div class="photo-section" id="pic">
                <span style="color: white; font-weight: 500;">会员照片加载中...</span>
            </div>
            <div class="basic-info-grid">
                <div class="info-group">
                    <div class="info-row">
                        <div class="info-label">姓名</div>
                        <div id="cusName" class="info-value"></div>
                    </div>
                    <div class="info-row">
                        <div class="info-label">性别</div>
                        <div id="sex" class="info-value"></div>
                    </div>
                    <div class="info-row">
                        <div class="info-label">电话</div>
                        <div id="mobile" class="info-value"></div>
                    </div>
                    <div class="info-row">
                        <div class="info-label">生日</div>
                        <div id="birthday" class="info-value"></div>
                    </div>
                </div>
                
                <div class="info-group">
                    <div class="info-row">
                        <div class="info-label">年龄</div>
                        <div id="age" class="info-value"></div>
                    </div>
                    <div class="info-row">
                        <div class="info-label">行业/职业</div>
                        <div id="indOcc" class="info-value"></div>
                    </div>
                    <div class="info-row">
                        <div class="info-label">客户来源</div>
                        <div id="cusSrc" class="info-value"></div>
                    </div>
                    <div class="info-row">
                        <div class="info-label">会员积分</div>
                        <div id="rewardPoints" class="info-value"></div>
                    </div>
                    <div class="info-row">
                        <div class="info-label">会员等级</div>
                        <div id="stage" class="info-value"></div>
                    </div>
                    <div class="info-row">
                        <div class="info-label">会员勋章</div>
                        <div id="badge" class="info-value"></div>
                    </div>
                </div>
                
                <div class="info-group">
                    <div class="info-row">
                        <div class="info-label">紧急联系人</div>
                        <div id="emgcCtct" class="info-value"></div>
                    </div>
                    <div class="info-row">
                        <div class="info-label">紧急电话</div>
                        <div id="emgcMobile" class="info-value"></div>
                    </div>
                    <div class="info-row">
                        <div class="info-label">地址</div>
                        <div id="addr" class="info-value"></div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 购课情况卡片 -->
        <div class="info-card">
            <div class="card-header">购课情况</div>
            <div class="stats-grid">
                <div class="stat-item">
                    <div class="stat-label">最后一次购课日期</div>
                    <div id="laBuyDate" class="stat-value">-</div>
                </div>
                <div class="stat-item" style="background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);">
                    <div class="stat-label">购课总金额 / 总次数</div>
                    <div id="totalBuy" class="stat-value">-</div>
                </div>
                <div class="stat-item" style="background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);">
                    <div class="stat-label">件均消费金额</div>
                    <div id="avrBuyPay" class="stat-value">-</div>
                </div>
            </div>
            
            <div class="detail-section">
                <div class="detail-header">
                    <div class="detail-title">购课详情</div>
                </div>
                <div id="buyDetail" class="detail-content"></div>
            </div>
        </div>

        <!-- 上课情况卡片 -->
        <div class="info-card">
            <div class="card-header">上课情况</div>
            <div class="stats-grid">
                <div class="stat-item" style="background: linear-gradient(135deg, #ff9a9e 0%, #fad0c4 100%);">
                    <div class="stat-label">最近一次上课日期</div>
                    <div id="laClsDate" class="stat-value">-</div>
                </div>
                <div class="stat-item" style="background: linear-gradient(135deg, #a18cd1 0%, #fbc2eb 100%);">
                    <div class="stat-label">上课总次数 / 上课总天数</div>
                    <div id="totalCls" class="stat-value">-</div>
                </div>
                <div class="stat-item" style="background: linear-gradient(135deg, #fbc2eb 0%, #a6c1ee 100%);">
                    <div class="stat-label">上课频率</div>
                    <div id="frqcy" class="stat-value">-</div>
                </div>
            </div>
            
            <div class="detail-section">
                <div class="detail-header">
                    <div class="detail-title">上课详情</div>
                </div>
                <div id="clsDetail" class="detail-content"></div>
            </div>
        </div>

        <!-- 上课时段图表 -->
        <div class="chart-container">
            <div class="chart-title">上课时段分布</div>
            <div id="clsHourQty"></div>
        </div>
    </div>

    <script src="../static/js/common.js"></script>
    <script src="../static/js/echarts.min.js"></script>
    
    <script>
        let insName;
        let insId;
        let insRole;
        let insList;
        let cus_list;
        let cusStageConfig;
        
        document.addEventListener('DOMContentLoaded',function(){
            // loginCheck();        
            const insInfo=hideInsSelectBlockAndGetInsInfo();
            insId=insInfo.sessionInsId;
            insName=insInfo.sessionInsName;
            insRole=insInfo.sessionInsRole;

            fetch('/get_cus_list', {
                method: 'GET',
                headers: {
                    'Content-Type': 'application/json'
                    }
                })
                .then(response => response.json())
                .then(data => {
                cus_list=data;
                  })
                .catch(error => console.error('Error:', error)); 

            getCusStageConfig();
            document.getElementById('stage').innerHTML='';
         
        });

        function getCusStageConfig(){
            fetch('/get_cus_stage_config', {
                method: 'GET',
                headers: {
                    'Content-Type': 'application/json'
                    }
                })
                .then(response => response.json())
                .then(data => {                
                cusStageConfig=data.stage_config;
                console.log('cusStageConfig list:',cusStageConfig);
                  })
                .catch(error => console.error('Error:', error)); 

        }

        function showCusStage(totalAmount){
            const ranges = Object.keys(cusStageConfig);
            let range = null;
            for (const rangeKey of ranges) {
            const [min, max] = rangeKey.split('-').map(Number);
            if (Math.round(totalAmount/10) >= Math.round(min/10) && Math.round(totalAmount/10) < Math.round(max/10)) {
                range = cusStageConfig[rangeKey];
                console.log('所在的range：',range);
                break;
            }
            }

            // 根据会员等级显示相应的勋章
            let badgeClass = '';
            let badgeText = range.name;
            
            switch(range.name) {
                case '心动行动':
                    badgeClass = 'badge badge-bronze';
                    break;
                case '渐入佳境':
                    badgeClass = 'badge badge-silver';
                    break;
                case '身体力行':
                    badgeClass = 'badge badge-gold';
                    break;
                case '知行合一':
                    badgeClass = 'badge badge-platinum badge-glow';
                    break;
                default:
                    badgeClass = 'badge badge-bronze';
            }

            document.getElementById('stage').innerHTML=`${range.star}`;
            document.getElementById('badge').innerHTML=`<div class="${badgeClass}">${badgeText}</div>`;
            document.getElementById('rewardPoints').innerHTML=`${Math.round(totalAmount/10,0)} 分`;
        }

               
        function handleInput() {
            const cusNameInput=document.getElementById('cusNameInput');
            const searchTerm = document.getElementById("cusNameInput").value.trim();
            const UpperSearchTerm=searchTerm.toUpperCase();
            const resultList = document.getElementById("cusNameList");
            const infoBox=document.getElementById('infoBox');
            infoBox.style.display='none';

            const pic=document.getElementById('pic');
            pic.innerHTML='';

            const insInfo=document.getElementById('insInfo');
            insInfo.innerHTML='';
            
            resultList.innerHTML = "";

            if (UpperSearchTerm === "") {
                resultList.style.display = "none";
                return;
            }else{
                resultList.style.display = "block";
                // 调整列表框位置，使其左上角贴紧输入框的右上角
                const inputRect = cusNameInput.getBoundingClientRect();
                resultList.style.left = (inputRect.left + inputRect.width) + 'px';
                resultList.style.top = inputRect.top + 'px';
                resultList.style.width = inputRect.width + 'px';
            }

            cus_list.reverse().forEach(function(name) {
                if (name.includes(UpperSearchTerm)) {
                    const listItem = document.createElement("li");
                    listItem.textContent = name;
                    
                    listItem.addEventListener("click", function() {                        
                        cusNameInput.value = name;
                        resultList.style.display = "none";

                        fetch('/get_cus_basic_info',{
                            method:'POST',
                            headers: {
                                'Content-Type': 'application/json'
                            },
                            body:JSON.stringify({'cusIdName':name})
                            })
                        .then(response=>response.json())
                        .then(basicData=>{
                            if(basicData['res']==='ok'){
                                showCusImg(name);
                                infoBox.style.display='block';
                                showBasic(basicData['data']);
                            }else{
                                infoBox.style.display='none';
                            }       
                        })
                        .catch(error=>{
                            console.log('获取会员基本信息错误：',error)
                        });                 
                        
                        fetch('/get_cus_info',{
                            method:'POST',
                            headers: {
                                'Content-Type': 'application/json'
                            },
                            body:JSON.stringify({'selected_name':name})
                            })
                        .then(response=>response.json())
                        .then(data=>{
                            showBuy(data);
                            showCls(data);                       
                        })
                        .catch(error=>{
                            console.log('获取既往上课错误：',error)
                        });      
                        
                        fetch('/get_cus_cls_hour_qty',{
                            method:'POST',
                            headers: {
                                'Content-Type': 'application/json'
                            },
                            body:JSON.stringify({'cusIdName':name})
                            })
                        .then(response=>response.json())
                        .then(data=>{
                            if(data['res']==='ok'){
                                showCusHourQty(data['data'],'clsHourQty');
                            }else{
                                const chartBox=document.getElementById('clsHourQtyBox');
                                chartBox.innerHTML='';
                            }                     
                        })
                        .catch(error=>{
                            console.log('获取会员上课时间段信息错误：',error)
                        });  
                        
                        fetch(`/get_cus_buy_sum?cus_id=${encodeURIComponent(name.slice(0,7))}`)
                        .then(response=>response.json())
                        .then(data=>{
                            if(data['res']==='ok'){
                                showCusStage(parseFloat(data.data[0]['total_amount']));
                            }else{
                               console.log('获取会员总购课金额错误：',data.msg)
                            }                     
                        })
                        .catch(error=>{
                            console.log('获取会员总购课金额错误：',error)
                        });  
                        
                        resultList.innerHTML = "";
                    });

                    resultList.appendChild(listItem);
                }
            });        
        }

        function showCusHourQty(cusHourQtyData,chartBoxId){
            const chartBox=document.getElementById(chartBoxId);
            chartBox.innerHTML='';
            const prds={
                '6':0,'7':0,'8':0,'9':0,'10':0,'11':0,'12':0,
                '14':0,'15':0,'16':0,'17':0,'18':0,'19':0,
                '20':0,'21':0,'22':0,'23':0                
            };

            if(cusHourQtyData){
                cusHourQtyData.forEach(rec=>{            
                    prds[rec[2].toString()]=rec[3];                   
                });
                const qtySum = Object.values(prds).reduce((acc, cur) => acc + cur, 0);
                if(qtySum>0){
                    const chart=showInsClsChart(prds);                    
                    chartBox.appendChild(chart);
                }
            }else{
                chartBox.innerHTML='';
            }
        }

        function showInsClsChart(prds){
            const chartContainer = document.createElement('div');
            chartContainer.id=insName;
            chartContainer.style.width='100%';
            chartContainer.style.height='200px';
            
            const chart = echarts.init(chartContainer);
            const xAxisData = Object.keys(prds);
            const totalData = Object.values(prds);
            const sum = totalData.reduce((accumulator, currentValue) => {
                return accumulator + currentValue;
            }, 0);

            const titleStr=`共${sum}节`;
            const options = {
                title: {
                    text: titleStr,
                    textStyle: {
                        color:'#5D88E6',
                        fontSize: 14
                    }
                },
                xAxis: {
                    type: 'category',
                    name:'时段',
                    data: xAxisData,
                    axisLabel: {
                        fontSize: 10
                    }
                },
                yAxis: [
                    {
                        type: 'value',
                        name: '上课节数',
                        position: 'left',
                        axisLabel: {
                            fontSize: 10
                        }
                    }
                ],
                series: [
                    {
                        name: '上课节数',
                        type: 'bar',
                        yAxisIndex: 0,
                        data: totalData,
                        itemStyle: {
                            color:'#5D88E6'
                        },
                        label: {
                            show: true,
                            position: 'top',
                            formatter: function (params) {
                                return params.value === 0 ? '' : params.value;
                            }
                        }
                    }
                ]
            };

            chart.setOption(options);
            
            // 添加窗口大小变化时的自适应
            window.addEventListener('resize', function() {
                chart.resize();
            });
            
            // 延迟重绘以确保图表正确显示
            setTimeout(() => {
                chart.resize();
            }, 100);
            
            return chartContainer;
        }

        function showCusImg(cusIdName){
            const pic=document.getElementById('pic');
            
            fetch('/get_cus_image', {
                    method: 'POST',
                    headers: {
                    'Content-Type': 'application/json'
                    },
                    body:JSON.stringify({'cusIdName':cusIdName})
                    })
                .then(response => response.blob())
                .then(blob => {
                    pic.innerHTML='';                  
                    const imageUrl = URL.createObjectURL(blob); 
                    const imgElement=document.createElement('img');
                    imgElement.style.height='130px';
                    imgElement.src = imageUrl;
                    imgElement.alt = '会员照片';
                    pic.appendChild(imgElement);
                })
                .catch(error => console.error('Error:', error));
        }

        function showBasic(data){
            const infoBox=document.getElementById('infoBox');
            const cusName=document.getElementById('cusName');
            const sex=document.getElementById('sex');
            const birthday=document.getElementById('birthday');
            const age=document.getElementById('age');
            const indOcc=document.getElementById('indOcc');
            const cusSrc=document.getElementById('cusSrc');
            const mobile=document.getElementById('mobile');
            const addr=document.getElementById('addr');
            const emgcContact=document.getElementById('emgcCtct');
            const emgcMobile=document.getElementById('emgcMobile');
            const insInfo=document.getElementById('insInfo');

            insInfo.innerHTML=`<h4 style='width:70px;'>教练</h4>${data[14]}`;
            
            cusName.innerHTML=`<span class='info-value'>${data[1]}</span>`;
            sex.innerHTML=`<span class='info-value'>${data[3]}</span>`;
            birthday.innerHTML=`<span class='info-value'>${dateToStringGmt(data[2],'date')}</span>`;
            age.innerHTML=`<span class='info-value'>${data[4]}岁</span>`;
            indOcc.innerHTML=`<span class='info-value'>${data[5]}/${data[6]}</span>`;
            if(`${data[5]}/${data[6]}`.length>15){
                indOcc.innerHTML=`<span class='info-value' style="font-size:12px;">${data[5]}/${data[6]}</span>`;
            }
            
            cusSrc.innerHTML=`<span class='info-value'>${data[8]}</span>`;
            mobile.innerHTML=`<span class='info-value'>${data[9]}</span>`;
            addr.innerHTML=`<span class='info-value'>${data[12]}</span>`;
            emgcContact.innerHTML=`<span class='info-value'>${data[10]}</span>`;
            emgcMobile.innerHTML=`<span class='info-value'>${data[11]}</span>`;
        }

        function showBuy(data){
            const laBuyDate=document.getElementById('laBuyDate');
            laBuyDate.innerHTML=`<span class='stat-value'>${data['最后一次购课日期']}</span>`;

            const totalBuy=document.getElementById('totalBuy');
            let totalBuyTimes=0;
            Object.keys(data).forEach(key=>{
                if(key.slice(0,4)==='购课次数'){
                    totalBuyTimes+=parseFloat(data[key]);
                }
            });
            totalBuy.innerHTML=`<span class='stat-value'>${data['总消费金额']} 元 / ${totalBuyTimes} 次</span>`;

            const avrBuyPay=document.getElementById('avrBuyPay');
            avrBuyPay.innerHTML=`<span class='stat-value'>${parseFloat(data['平均每单消费金额']).toFixed(2)} 元</span>`;

            const buyDetail=document.getElementById('buyDetail');
            buyDetail.innerHTML='';
            
            let pay={};
            Object.keys(data).forEach(key=>{
                if(key.slice(0,4)==='消费金额'){
                        pay[key]=data[key];       
                }
            });

            let buyTimes={};
            Object.keys(data).forEach(key=>{
                if(key.slice(0,4)==='购课次数'){
                    if(parseFloat(data[key])>0){
                        buyTimes[key]=data[key];
                    }                   
                }
            });

            Object.keys(buyTimes).forEach(timesKey=>{
                const buyKey=timesKey.slice(4,);
                const detailItem=document.createElement('div');
                detailItem.className='detail-item';
                detailItem.innerHTML=`
                    <div style="font-size:12px;color:#64748b;margin-bottom:4px;">${timesKey.split('-')[1]} · ${timesKey.split('-')[2]}</div>
                    <div style="font-size:14px;font-weight:500;">${pay['消费金额'+buyKey]} 元 / ${buyTimes[timesKey]} 次</div>
                `;
                buyDetail.appendChild(detailItem);
            });
        }

        function showCls(data){
            const totalCls=document.getElementById('totalCls');
            totalCls.innerHTML=`<span class='stat-value'>${data['上课总次数']} 次 / ${data['上课总天数']} 天</span>`;
            
            const frqcy=document.getElementById('frqcy');
            frqcy.innerHTML=`<span class='stat-value'>${parseFloat(data['上课频率']).toFixed(2)} 天/周</span>`;
            
            const laClsDate=document.getElementById('laClsDate');
            laClsDate.innerHTML=`<span class='stat-value'>${data['最后一次上课日期']}</span>`;

            const clsDetail=document.getElementById('clsDetail');
            clsDetail.innerHTML='';
            
            Object.keys(data).forEach(key=>{
                if(key.slice(0,4)==='上课次数'){
                    if(parseFloat(data[key])>0){
                        const detailItem=document.createElement('div');
                        detailItem.className='detail-item';
                        detailItem.innerHTML=`
                            <div style="font-size:12px;color:#64748b;margin-bottom:4px;">${key.split('-')[1]} · ${key.split('-')[2]}</div>
                            <div style="font-size:14px;font-weight:500;">${data[key]} 次</div>
                        `;
                        clsDetail.appendChild(detailItem);
                    }
                }
            });
        }
    </script>
  
</body>
</html>
